package com.hg.controller;

import com.hg.dao.UserDao;
import com.hg.entity.User;
import com.hg.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: skh
 * @Date: 2019/12/19 10:35
 * @Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserServiceImpl userService;

    @Autowired
    private UserDao userDao;

    @GetMapping("/addUserToMaster")
    public String addUserToMaster(String name) {
        userService.addUserToMaster(name);
        return "success";
    }

    @GetMapping("/addUserToSlave")
    public String addUserToSlave(String name) {
        userService.addUserToSlave(name);
        return "success";
    }

    @GetMapping("/listFromMaster")
    public String listFromMaster() {
        userService.listFromMaster();
        return "success";
    }

    @GetMapping("/listFromSlave")
    public String listFromSlave() {
        userService.listFromSlave();
        return "success";
    }


    @GetMapping("/test")
    public String test() {
        User user = userDao.selectById(1);
        System.out.println("user = " + user);
        return "success";
    }

    @GetMapping("/testInsert")
    public String testInsert() {
        userService.addUser();
        return "success";
    }
}
